/**
 * HT1621 液晶屏驱动
 * Copyright (c) 2021 深圳市智辰科技有限公司
 * All rights reserved.
 */

#include <soc/rtc.h>
#include <soc/timer_group_struct.h>
#include <driver/periph_ctrl.h>
#include <driver/timer.h>
#include <sys/time.h>

#include "stdc.h"
#include "sys_clock.h"

long osGetTime() {
	struct timeval val;
	gettimeofday(&val, NULL);
	return val.tv_sec;
}

struct tm osGetLocalDateTime() {
	time_t now;
	struct tm timeinfo;

	time(&now);

	// Set timezone to China Standard Time
	setenv("TZ", "CST-8", 1);
	tzset();

	localtime_r(&now, &timeinfo);
	return timeinfo;
}

char* osGetLocalDateTimeString() {
	static char str[64];
	struct tm timeinfo = osGetLocalDateTime();
	strftime(str, sizeof(str), "%c", &timeinfo);
	return str;
}
